package com.xxx.client.android.dialog;

import android.app.Activity;
import android.content.Intent;

import com.xxx.client.android.activity.MarqueeListActivity;
import com.xxx.client.android.api.MarqueeListEntry;
import com.xxx.client.android.api.WSError;
import com.xxx.client.android.api.XXXApi;
import com.xxx.client.android.api.impl.XXXApiImpl;

public class MarqueeListLoadingDialog extends
		LoadingDialog<Void, MarqueeListEntry> {

	public MarqueeListLoadingDialog(Activity activity, int loadingMsg,
			int failMsg) {
		super(activity, loadingMsg, failMsg);
	}

	/**
	 * @param params
	 *            params[0]:keyword params[1]:type params[2]:submenuId
	 *            params[3]:submenuName
	 * */
	@Override
	public MarqueeListEntry doInBackground(Void... params) {

		XXXApi service = new XXXApiImpl();
		MarqueeListEntry marqueeList = null;
		try {
			marqueeList = service.getMarqueeList();
		} catch (RuntimeException e) {
			e.printStackTrace();
			return null;
		} catch (WSError e) {
			publishProgress(e);
			cancel(true);
		}
		return marqueeList;

	}

	@Override
	public void doStuffWithResult(MarqueeListEntry marqueeList) {

		Intent intent = new Intent(mActivity, MarqueeListActivity.class);

		intent.putExtra("marqueeList", marqueeList);
		mActivity.startActivity(intent);
		if (mActivity instanceof MarqueeListActivity) {
			mActivity.finish();
		}
	}

}
